//
//  LOTableViewCell.m
//  LegalObserver
//
//  Created by Roxanne Brittain on 10/30/11.
//  Copyright (c) 2011 Digifit. All rights reserved.
//

#import "FFTableViewCell.h"

#define kTextFieldFrame CGRectMake(200, 11, 190, 24)
#define kTextLabelFrame CGRectMake(0, 11, 190, 24)

@implementation FFTableViewCell
@synthesize titleLabel, textField, key, delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        titleLabel = [UILabel new];
        titleLabel.frame = kTextLabelFrame;
        titleLabel.textAlignment = UITextAlignmentLeft;
        titleLabel.backgroundColor = [UIColor clearColor];
        titleLabel.font = [UIFont boldSystemFontOfSize:16];
        titleLabel.textColor = [UIColor darkTextColor];
        [self.contentView addSubview:titleLabel];
        
        textField = [UITextField new];
        textField.frame = kTextFieldFrame;
        titleLabel.textAlignment = UITextAlignmentRight;
        textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        textField.borderStyle = UITextBorderStyleNone;
        textField.delegate = self;
        textField.returnKeyType = UIReturnKeyDone;
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self.contentView addSubview:textField];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}

-(void)didSelectCell
{
    [textField becomeFirstResponder];
}

-(BOOL)textFieldShouldReturn:(UITextField *)tf
{
    [tf endEditing:YES];
    return YES;
}

-(void)textFieldDidEndEditing:(UITextField *)tf
{
    [delegate textFieldWithKey:key updatedWithText:tf.text];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
